package com.platform.database.server;

import java.util.concurrent.CountDownLatch;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.platform.common.utils.log.LoggerFactory;

/**
 * Created by flying on 16-10-9.
 */
public class PlatformDatabaseServerProvider {


    private final static String applicationContext = "spring/applicationContext.xml";

    public static void main(String[] args) throws InterruptedException {
    	System.setProperty("production.mode", "ONLINE");
    	
        final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(applicationContext);
        
        context.start();
        LoggerFactory.get().debug("platform database server is starting!!!!!");

        final CountDownLatch latch = new CountDownLatch(1);

        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
            	LoggerFactory.get().debug("platform database server is stopping!!!!!");
                context.destroy();
                latch.countDown();
            }
        });

        latch.await();

        LoggerFactory.get().debug("platform database server is stopped!!!!!");
        context.close();
    }
}
